<?php
/**
 * Created by PhpStorm.
 * User: hang
 * Date: 2021/12/15
 * Time: 12:00
 */
include_once '../user/common.php';
include_once '../tools/DbTools.php';
$is_login = getLoginStatus();
if (!$is_login){
    echo '尚未登录，<a href="../user/loginUi.php"></a>';
    die;
}else{
    $OutMoney = $_POST['OutMoney'];
    $token = $_COOKIE['Token'];
    $userInfo = $_SESSION[$token];
    $CardId = $userInfo['CardId'];
    DbTools::initDb();
    $sql = "select CardMoney from bankcard where CardId='$CardId'";
    $result = DbTools::select($sql);
    $money = $result[0]['CardMoney'];
    if ($OutMoney>$money){
        echo '余额不足！<a href="moneyOut.php">重新输入</a>';
        die;
    }else{
        $sql = "update bankcard set CardMoney=CardMoney-$OutMoney where CardId='$CardId'";
        DbTools::noSelect($sql);
        DbTools::close();
        echo "<h2>取钱成功！<br/><a href=\"moneyOut.php\">继续取钱</a><br/><a href=\"../user/userInfo.php\">用户中心</a></h2>";
    }

}